var base = '';
/**
 * Ajax Post工具类
 */
var regEx = {
	money : /^[0-9]+(\.[0-9]{1,2})?$/,
	bankid: /^\d+$/,
	scoreb: /^\d+$/,
	m_username: /^[a-zA-Z0-9]{5,20}$/,
	m_password : /^(.){6,20}$/
};

String.prototype.trim=function(){
   return this.replace(/(^\s*)|(\s*$)/g, "");
}

String.prototype.endWith=function(str){
	if(str==null||str==""||this.length==0||str.length>this.length)
		return false;
	if(this.substring(this.length-str.length)==str)
		return true;
	else
		return false;
	return true;
}

String.prototype.startWith=function(str){
	if(str==null||str==""||this.length==0||str.length>this.length)
		return false;
	if(this.substr(0,str.length)==str)
		return true;
	else
		return false;
	return true;
}

function ajaxUtil(url,params,loding_img,dataType,method,callMethod){
	if(params){
		params.req_type='ajax';
	}else{
		params={req_type:'ajax'};
	}
	if(loding_img)
		loding_img.show();
	$.ajax({
		type: method,
        data : params,
        dataType: dataType,
        url: url,
		complete :function(){
			if(loding_img)
				loding_img.hide();
		},
		success : function(data){
			if(data){
				if(data.status){
					if(data.redirectionUrl){
						if(data.message)
							window.alert(data.message);
						window.location.href = data.redirectionUrl;
						return false;
					}
				}
				callMethod(data);
			}else{
				window.parent.parent.parent.location.href = login_url;
			}
		}
	});	
}

function ajaxPost(url, params, loding_img, dataType, callMethod) {
	if (params) {
		params.req_type = 'ajax';
	} else {
		params = {
			req_type : 'ajax'
		};
	}
	if (loding_img)
		loding_img.show();
	$.ajax( {
		type : "post",
		data : params,
		dataType : dataType,
		url : url,
		complete : function() {
			if (loding_img)
				loding_img.hide();
		},
		success : function(data) {
			if (data) {
				if (data.status) {
					if (data.redirectionUrl) {
						if (data.message)
							window.alert(data.message);
						window.location.href = data.redirectionUrl;
						return false;
					}
				}
				callMethod(data);
			} else {
				window.location.href = login_url;
			}
		},
		error : function(){
			window.alert('访问异常，请稍后再试');
		}
	});
}
var upmemberstatuURL = base + '/admin/member!upmemberstatu.action';
function upmemberstatu(id, username, statu) {
	var msg = statu == 1 ? '您确定要对' + username + '的账号进行解锁操作吗?'
			: '您确定要对' + username + '的账号进行锁定操作吗?';
	if (!confirm(msg)) {
		return false;
	}
	ajaxPost(upmemberstatuURL, {
		'id' : id,
		'statu' : statu
	}, null, 'json', upmemberstatuCallback);
	return false;
}

function upmemberstatuCallback(data) {
	if (data.status) {
		if (data.status == 'success') {
			window.location.href = window.location.href;
		} else {
			window.alert(data.message);
		}
	} else {
		window.alert('系统繁忙，请稍后再试');
	}
}
var upmailstatuURL = base + 'admin/mail!upmailstatu.action';
function upmailstatu(id, isclose) {
	ajaxPost(upmailstatuURL, {
		'id' : id,
		'isclose' : isclose
	}, null, 'json', upmailstatuCallback);
	return false;
}

function upmailstatuCallback(data) {
	if (data.status) {
		if (data.status == 'success') {
			window.location.reload();
		} else {
			window.alert(data.message);
		}
	} else {
		window.alert('系统繁忙，请稍后再试');
	}
}

var upmembersecpwdURL = base + '/admin/member!upmembersecpwd.action';
function upmembersecpwd(id, username) {
	if (!confirm('您确定重置' + username + '用户的密保卡吗？')) {
		return false;
	}
	ajaxPost(upmembersecpwdURL, {
		'id' : id
	}, null, 'json', callReload);
	return false;
}

var upmemberzzstateURL = base + '/admin/member!upmemberzzstate.action';
function upmemberzzstate(uid, state, username) {
	var msg = state == 1 ? '您确定要对' + username + '的进行转账解锁操作吗?'
			: '您确定要对' + username + '的账户进行转账锁定操作吗?';
	if (!confirm(msg)) {
		return false;
	}
	ajaxPost(upmemberzzstateURL, {
		'uid' : uid,
		'state' : state
	}, null, 'json', callReload);
	return false;
}

function reloadmail() {
	ajaxPost(base + '/admin/mail!reloadmail.action', null, null, 'json',
			ajaxCallback);
	return false;
}

function callReload(data) {
	window.alert(data.message);
	if (data.status == 'success') {
		window.location.reload();
	}
}

function ajaxCallback(data) {
	if (data.message) {
		window.alert(data.message);
	}
}

function closeMyDiv(obj) {
	obj.CloseDiv();
}

function upstatusShow(userid, username, status) {
	var title = '';
	if (status == 1) {
		title = '您确定对<font color="red">' + username + '</font>进行领币<font color="red">解锁</font>操作吗？';
	} else {
		title = '您确定对<font color="red">' + username + '</font>进行领币<font color="red">锁定</font>操作吗？';
	}
	$('#title_s').html(title);
	$('#userid_s').val(userid);
	$('#status_s').val(status);
	$('#divSCA1').OpenDiv();
}

var upadminstatuURL = base+'/admin/transaction!upadminstatu.action';
function upstatus() {
	var userid = $('#userid_s').val();
	var status = $('#status_s').val();
	var statusdesc = $('#statusdesc').val();
	if (userid == '') {
		window.alert('选择的用户不能为空');
		return false;
	}
	if (status == '') {
		window.alert('编辑用户状态参数有误');
		return false;
	}
	ajaxPost(upadminstatuURL, {
		'userid' : userid,
		'status' : status,
		'statusdesc' : statusdesc
	}, null, 'json', callReload);
}

function payoffShow(userid, username) {
	var title = '您将要对<font color="red">' + username + '</font>进行收币操作';
	$('#payoff_title').html(title);
	$('#userid_p').val(userid);
	$('#divSCA2').OpenDiv();
}

var payoffURL = base+'/admin/transaction!payoff.action';
function payoff(){
	var apppayoffmx=$("#apppayoffmx").children();
	var banks = '';
	var moneys = '';
	var in_b = $('#in_b');
	var userid = $('#userid_p');
	if(userid == ''){
		window.alert('请选择要还款的用户');
		return false;
	}
	if(!regEx.scoreb.test(in_b.val())){
		window.alert('请输入的积分币格式有误，必须为整数');
		in_b.select();
		return false;
	}
	for(var i = 0 ; i < apppayoffmx.length ; i++){
		var bankid = $(apppayoffmx[i]).find('select');
		var money = $(apppayoffmx[i]).find('input[name=money]');
		if(!regEx.bankid.test(bankid.val())){
			window.alert('请选择银行');
			return false;
		}
		if(!regEx.money.test(money.val())){
			window.alert('输入的金额格式有误，必须为数字，最多保留2位小数');
			money.select();
			return false;
		}
		banks += bankid.val();
		moneys += money.val();
		if(i < apppayoffmx.length - 1){
			banks += ';';
			moneys += ';';
		}
	}
	ajaxPost(payoffURL, {
		'userid' : userid.val(),
		'in_b' : in_b.val(),
		'banks' : banks,
		'moneys' : moneys
	}, null, 'json', callReload);
}

function uplimitaccShow(userid, username){
	var title = '您将要对<font color="red">' + username + '</font>进行领币额度设置操作';
	$('#title_lm').html(title);
	$('#userid_lm').val(userid);
	$('#divSCA3').OpenDiv();
}

var uplimitaccURL = base+'/admin/transaction!uplimitacc.action';
function uplimitacc() {
	var userid = $('#userid_lm').val();
	var limit_acc = $('#limit_acc');
	if (userid == '') {
		window.alert('选择的用户不能为空');
		return false;
	}
	if (!regEx.scoreb.test(limit_acc.val())) {
		window.alert('额度设置有误，只能为整数');
		limit_acc.select();
		return false;
	}
	ajaxPost(uplimitaccURL, {
		'userid' : userid,
		'limit_acc' : limit_acc.val()
	}, null, 'json', callReload);
}

function savehadminShow(){
	$('#divSCA4').OpenDiv();
}

var savehadminURL = base+'/admin/transaction!savehadmin.action';
function savehadmin(){
	var username = $('#username_add');
	var limit_acc = $('#limit_acc_add');
	if (username.val() == '') {
		window.alert('用户名不能为空');
		username.select();
		return false;
	}
	if (!regEx.scoreb.test(limit_acc.val())) {
		window.alert('额度设置有误，只能为整数');
		limit_acc.select();
		return false;
	}
	ajaxPost(savehadminURL, {
		'username' : username.val(),
		'limit_acc' : limit_acc.val()
	}, null, 'json', callReload);
}

function bindmuShow(){
	$('#divSCA1').OpenDiv();
}

var bindmuURL = base+'/admin/transaction!bindmu.action';
function bindmu(){
	var m_username = $('#m_username');
	var m_password = $('#m_password');
	if(!regEx.m_username.test(m_username.val())){
		window.alert('用户名格式错误，长度为5-20字母或数字');
		m_username.select();
		return false;
	}
	if(!regEx.m_password.test(m_password.val())){
		window.alert('用户名格式错误，长度为6-20位');
		m_password.select();
		return false;
	}
	ajaxPost(bindmuURL, {
		'm_username' : m_username.val(),
		'm_password' : m_password.val()
	}, null, 'json', callReload);
}

var getbURL = base+'/admin/transaction!getb.action';
function getb(){
	if(!window.confirm("您确定要领取积分币吗?")){
		return false;
	}
	ajaxPost(getbURL, null, null, 'json', callReload);
}